package com.peakmain.baselibrary.widget.loading;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * author ：Peakmain
 * createTime：2019/4/13
 * mail:2726449200@qq.com
 * describe：
 */
public class CircleView extends View {
    private int mColor;
    private Paint mPaint;
    public CircleView(Context context) {
        this(context,null);
    }

    public CircleView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public CircleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mPaint=new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);//防抖动
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        float cx=getWidth()/2;
        float cy=getHeight()/2;

        canvas.drawCircle(cx,cy,cx,mPaint);
    }
    //切换颜色
    public void exchangeColor(int color){
        this.mColor=color;
        mPaint.setColor(mColor);
        invalidate();
    }

    public int getColor() {
        return mColor;
    }
}
